<?php

namespace app\admin\controller;

use app\common\controller\Backend;
use think\Config;

/**
 * 控制台
 *
 * @icon fa fa-dashboard
 * @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
 */
class Dashboard extends Backend
{

    /**
     * 查看
     */
    public function index()
    {
        $seventtime = \fast\Date::unixtime('day', -7);
        $paylist = $createlist = [];
        for ($i = 0; $i < 7; $i++)
        {
            $day = date("Y-m-d", $seventtime + ($i * 86400));
            $createlist[$day] = mt_rand(20, 200);
            $paylist[$day] = mt_rand(1, mt_rand(1, $createlist[$day]));
        }
        $hooks = config('addons.hooks');
        $uploadmode = isset($hooks['upload_config_init']) && $hooks['upload_config_init'] ? implode(',', $hooks['upload_config_init']) : 'local';
        $addonComposerCfg = ROOT_PATH . '/vendor/karsonzhang/fastadmin-addons/composer.json';
        Config::parse($addonComposerCfg, "json", "composer");
        $config = Config::get("composer");
        $addonVersion = isset($config['version']) ? $config['version'] : __('Unknown');
        
        //总文章数
        $article =  db('article')->count();
        
        //总单页数
        $page =  db('page')->count();
       
        //总院校数
        $yuanxiao =  db('yuanxiao')->count();

        //总分类数目
        $category =  db('category')->count();
        
        //专业管理--专升本
        $zhuanye =  db('zhuanye')->count();
        
        //专业管理--专升本
        $zikaozhuanye =  db('zikaozhuanye')->count();
        
        //附件统计
        $attachment =  db('attachment')->count();
        
        //日志统计
        $admin_log =  db('admin_log')->count();
        
        //最新的文章
        $articlelist = db('article')->order('weigh','desc')->limit(9)->select();
        
        $this->view->assign([
            'article'        => $article,
            'page'           => $page,
            'yuanxiao'       => $yuanxiao,
            'category'       => $category,
            'zhuanye'        => $zhuanye,
            'zikaozhuanye'   => $zikaozhuanye,
            'attachment'     => $attachment,
            'admin_log'      => $admin_log,
            'paylist'        => $paylist,
            'createlist'     => $createlist,
            'addonversion'   => $addonVersion,
            'uploadmode'     => $uploadmode,
        	'articlelist'    => $articlelist
        ]);

        return $this->view->fetch();
    }

}
